<?php
/**
 * Created by PhpStorm.
 * User: 胥九庆
 * Date: 2023/01/07
 * Time: 11:25
 */
declare (strict_types=1);

namespace app\api\controller;

use app\common\tool\Result;
use think\Response;
use app\common\model\StockRight as StockRightModel;

class StockRight extends Base
{
    public function index(): Response
    {
        $list = StockRightModel::getPageList([], 'id,stock_code,company_name,describe,img,create_time', $this->getPage(), $this->getLimit());
        return Result::fastReturn($list);
    }

    public function info(): Response
    {
        $id = $this->request->param('id');
        $info = StockRightModel::where('id', $id)->field('id,stock_code,company_name,describe,img,content,create_time,status,is_del')->find();
        if (empty($info) || $info->status != 1 || $info->is_del) {
            return Result::fail('记录不存在');
        }
        unset($info->status);
        unset($info->is_del);
        $url = 'https://' . $_SERVER['SERVER_NAME'] . '/uploads/';
        $info->content = htmlspecialchars_decode(str_replace('/uploads/', $url, $info->content));
        $info->content = str_replace('\\', '', $info->content);

        return Result::success('success', $info);
    }
}